package com.itheima.appserver.controller;

import com.itheima.appserver.service.CommentService;
import com.itheima.commons.pojo.Comment;
import com.itheima.commons.vo.PageResult;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: lqTao
 * @Date: 2021/12/9 23:13
 */
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    CommentService commentService;

    //查询评论列表
    @GetMapping
    public ResponseEntity queryComment(@RequestParam("movementId")String publishId,
                                       @RequestParam("page")Integer page,
                                       @RequestParam("pagesize")Integer pagesize) {


        PageResult pageResult = commentService.queryComment(publishId,page,pagesize,Comment.class);
        return ResponseEntity.ok(pageResult);
    }
    //提交评论
    @PostMapping
    public ResponseEntity commitComment(@RequestParam Map<String, Object> params) {
        commentService.commitComment(params);
        return ResponseEntity.ok(null);
    }

    //评论点赞
    @GetMapping("/{id}/like")
    public ResponseEntity likeComment(@PathVariable("id")String publishId ) {
        Long along = commentService.comment(publishId,2,Comment.class);
        return ResponseEntity.ok(along);
    }

    //评论取消点赞
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislikeComment(@PathVariable("id")String publishId) {
        Long along =commentService.disComment(publishId,1, Comment.class);
        return ResponseEntity.ok(along);
    }
}
